package com.zhangxiaofanfan.hotcode.third;

/**
 * TODO
 *
 * @author zhangxiaofanfan
 * @date 2024-05-24 10:34:02
 */
public class HotCode013 {
    public static void main(String[] args) {
        int[] nums = {1};
        HotCode013 hotCode013 = new HotCode013();
        System.out.println(hotCode013.maxSubArray(nums));
    }

    public int maxSubArray(int[] nums) {
        if (nums == null || nums.length == 0) {
            throw new IllegalArgumentException("Invalid input, nums is null or empty.");
        }
        int maxSum = Integer.MIN_VALUE;
        int curSum = 0;
        for (int num : nums) {
            curSum += num;
            maxSum = Math.max(curSum, maxSum);
            curSum = Math.max(curSum, 0);
        }
        return maxSum;
    }
}
